<template>
  <div style="padding: 24px">
    <!-- <el-button type="primary" @click="handleAdd">新增</el-button>
    <el-button
      type="primary"
      @click="handleExport"
      v-hasPermi="['bus:active:export']"
      >导出</el-button
    > -->
    <h2>用户列表</h2>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column type="index" width="50"> </el-table-column>
      <el-table-column label="账号" prop="memberId" width="180">
      </el-table-column>
      <el-table-column
        width="180"
        label="推广码"
        prop="promCode"
      ></el-table-column>
      <el-table-column label="注册时间" prop="createTime"></el-table-column>
            <el-table-column label="注册平台" width="120" prop="platform"></el-table-column>
      <el-table-column label="激活IP" prop="memberIp"></el-table-column>

      <el-table-column
        width="180"
        label="邀请人"
        prop="pMemberId"
      >
       <template slot-scope="scope">
          <el-tag v-if="!scope.row.pMemberId" type="danger">暂无</el-tag>
          <el-tag v-if="scope.row.pMemberId" >{{scope.row.pMemberId}}</el-tag>
           
        </template>
      </el-table-column>
      <el-table-column width="180" label="推广人数">
        <template slot-scope="scope">
          <el-tag> {{ scope.row.promotionStatistics.memberSize || 0 }}</el-tag
          >人
        </template>
      </el-table-column>
      <el-table-column width="180" label="扣量" prop="rebatePercent">
        <template slot-scope="scope">
          <el-tag> {{ scope.row.rebatePercent }}%</el-tag>
        </template>
      </el-table-column>
      <el-table-column  label="推广明细" prop="promotionStatistics">
        <template slot-scope="scope">
          <div
            v-show="scope.row.promotionStatistics.promotionList.length!=0"
            v-for="(item, index) in scope.row.promotionStatistics
              .promotionList "
            :key="index"
          >
            {{
              item.promPackageVip == "99999"
                ? "永久"
                : item.promPackageVip + "天"
            }}套餐：<el-tag> {{ item.promPackageNum }}</el-tag> 
            <!-- 金额：<el-tag>{{item.promPackageBeAmount}}</el-tag>  元
            推广员可见金额： <el-tag>{{item.promPackageAfAmount}}</el-tag> 元 -->
          </div>
          <div v-show="scope.row.promotionStatistics
              .promotionList.length==0">暂无</div>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleAdd(scope.row)" type="text" size="small"
            >修改</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      style="float: right"
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-size="limit"
      layout="total, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
    <el-dialog
      title="修改扣量"
      :visible.sync="dialogFormVisible"
      width="580px"
      :close-on-click-modal="false"
    >
      <el-form :model="form">
        <el-form-item label="推广员" :label-width="formLabelWidth">
          <el-input v-model="form.memberId" disabled autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="扣量比" :label-width="formLabelWidth">
          <el-input
            type="number"
            max="100"
            min="0"
            v-model.number="form.rebatePercent"
            autocomplete="off"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import request from "@/utils/request";
export default {
  data() {
    return {
      tableData: [],
      total: 0,
      limit: 20,
      page: 1,
      dialogFormVisible: false,
      dictCodeList: [],
      form: {
        memberId: "",
        rebatePercent: 0,
      },
      formLabelWidth: "60px",
    };
  },
  created() {
    this.getSaleList();
  },
  methods: {
    getSaleList() {
      request({
        url:
          "/bus/member/list?pageSize=" + this.limit + "&pageNum=" + this.page,
        method: "get",
      }).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
      });
    },
    handleCurrentChange(page) {
      this.page = page;
      this.getSaleList();
    },
    handleAdd(e) {
      this.form.memberId = e.memberId;
      this.form.rebatePercent = e.rebatePercent;
      this.dialogFormVisible = true;
    },
    handleSubmit() {
      request({
        url: "/bus/active",
        method: "post",
        data: this.form,
      }).then((res) => {
        this.page=1
        this.getSaleList();
        alert("添加成功");
      });
      this.dialogFormVisible = false;
      console.log(this.form);
    },
    handleExport() {
      request({
        url: "/bus/active/export",
        method: "get",
      }).then((res) => {
        window.location.href =
          process.env.VUE_APP_BASE_API +
          "/common/download?fileName=" +
          encodeURI(res.msg) +
          "&delete=" +
          true;
      });
    },
  },
};
</script>